package com.ssmTest.controller;

import com.ssmTest.model.Services;
import com.ssmTest.service.IServiceService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

import static com.sun.corba.se.spi.activation.IIOP_CLEAR_TEXT.value;

@Controller
public class ServiceController {
    @Resource
    private IServiceService iServiceService;

    //返回审核列表
    @RequestMapping("/serviceList")
    public String serviceList(HttpSession session, ModelMap modelMap) {
        List<Services> list = null;
        list = iServiceService.ServiceList(0);
        modelMap.addAttribute("list", list);
        return "serviceList";
    }

//    //审核成功
//    @RequestMapping("/servicesSuccess.do")
//    public String servicesSuccess(HttpSession session, int id, ModelMap modelMap) {
//        Services services=iServiceService.selectService(id);
//        services.setToexamine(1);
//        iServiceService.updateService(services);
//        List<Services> list = null;
//        list=iServiceService.ServiceList(0);
//        modelMap.addAttribute("list",list);
//        return "serviceList";
//    }
//
//
//    //审核失败
//    @RequestMapping("/servicesFail.do")
//    public String servicesFail(HttpSession session, String reasion, ModelMap modelMap) {
//        System.out.println(reasion+"  "+session.getAttribute("sid"));
//        Services services=iServiceService.selectService(Integer.parseInt(session.getAttribute("sid").toString()));
//        services.setFail_reasion(reasion);
//        services.setToexamine(2);
//        iServiceService.updateService(services);
//        return "success";
//    }

    //本地服务列表弹出界面
    @RequestMapping("/servicesExl.do")
    public String servicesExl(ModelMap modelMap, int id) {
        Services services = iServiceService.selectService(id);
        modelMap.addAttribute("services", services);
        return "serviceExl";
    }

    //更新服务
    @RequestMapping(value = "/subService.do", method = RequestMethod.POST)
    public String subService(Services services) {
        System.out.println(services.getId());
        if (iServiceService.updateServiceALL(services) == 0)
            return "error";
        return "success";
    }

    //删除服务
    @RequestMapping("/delService.do")
    public String delService(int id) {
        iServiceService.delService(id);
        return "success";
    }
}
